package leecode

func mergeArrays(nums1 [][]int, nums2 [][]int) [][]int {
	maxId := 0
	hashMap := make(map[int]int) //key为对应的id , value为和
	for i := 0; i < len(nums1); i++ {
		maxId = max(nums1[i][0], maxId)
		hashMap[nums1[i][0]] += nums1[i][1]
	}
	for i := 0; i < len(nums2); i++ {
		maxId = max(nums2[i][0], maxId)
		hashMap[nums2[i][0]] += nums2[i][1]
	}
	var result [][]int
	for i := 1; i <= maxId; i++ {
		if sum, ok := hashMap[i]; ok {
			result = append(result, []int{i, sum})
		}
	}
	return result
}
